import {
	getDicts
} from "@/api/system/dict/data";
export default function(Vue, options) {
	Vue.mixin({
		data() {
			return {
				dicts:{},
				dictMap:{},
			}
		},
		created() {
			if (Array.isArray(this.$options.dicts)) {
				let arr = this.$options.dicts
				arr.map(res => {
					let name = res;
					this.$set(this.dicts,res,[])
					this.$set(this.dictMap,res,{})

					getDicts(res).then(response => {
						if(Array.isArray(response.data)) {
							let list = response.data.map(res=>{
								this.$set(this.dictMap[name],res.dictValue,res.dictLabel)
								return {
									[options.dictLabel]: res.dictLabel,
									[options.dictValue]: res.dictValue,
								}
							})
							this.dicts[res] = list
							// this.$forceUpdate()
							// this.$set(this.dicts,res,list)
						}
					});
				})
			}
		}
	})
}